#pragma once
#include <map>
#include <iomanip>
#include <array>
#include <clocale>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>
#include "StopWatch.h"
using namespace std;
namespace TentamenVersion1
{
	class NilsHolgersson
	{
	private:
		map<string, int> Dict;
	public:

		NilsHolgersson()
		{
		}

		void ReadFromFile(string fileName)
		{

			try
			{
				ifstream fin("nils_holgersson.txt");

				while (!fin.eof())
				{
					string s;
					fin >> s;

					auto it = Dict.find(s);

					if (it != Dict.end())
					{
						it->second++;
					}

					else
					{
						Dict.emplace(s, 1);
					}
				}

				fin.close();

			}
			


			catch (exception e)
			{
				cerr << "Exception: " << fileName << endl;
				cerr << e.what() << endl;
			}

		}

		void FindMaxElement()
		{
			auto it = std::max_element(Dict.begin(), Dict.end(), cmp);
			cout << "Ord: " << it->first << ", antal: " << it->second << endl;

		}

		static bool cmp(pair<string, int> lop, pair<string, int> rop)
		{
			return lop.second < rop.second;
		}
		~NilsHolgersson()
		{
		}
	};
}

